<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>修改密码</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src="js/addressinitialization.js"></script>
		
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/forcedissonionPassword.css"/>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript">
			mui.init();
			window.onload=function(){
				update_but();
			}
    	/*修改密码按钮*/
		function update_but(){
			document.getElementById("forceupdate_but").addEventListener('click',function(){
				var getuser_url=IP+'/ias/Forced'
				var oldpassword=mui("#oldpassword")[0].value;
				var newpassword=mui("#newpassword")[0].value;
				var truepassword=mui("#truepassword")[0].value;
				//验证两次密码是否一致
				if(newpassword==truepassword){
					//两次密码一致
					//验证密码强度等级
					var Grade=checkPass(truepassword);
					if(Grade==3){
						mui.ajax(getuser_url,{
						data:{
							oldpassword : oldpassword,
							newpassword : truepassword
						},
						type:'post',
						tdataType:'json',
						timeout: 10000,
						headers:{'Content-Type':'application/json'},
						beforeSend: function(data) {
      						plus.nativeUI.showWaiting("密码校验修改中");
   				 		},
						success:function(data){
							var result=data.result;
								var msg=data.msg;
								if(result == 'error'){
									//修改失败
									if(msg=="登陆状态异常，请重新登陆"){
										mui.toast(msg);
										plus.runtime.restart();
									}else{
										mui.toast(msg);
									}
									plus.nativeUI.closeWaiting();
								}else{
									//修改成功
									plus.nativeUI.closeWaiting();
									mui.toast(msg+",正在返回登陆");
									try{
										plus.runtime.restart();
									}catch(e){
										mui.toast("跳转失败");
									}
								}
						},
						error:function(){
							mui.toast("请求失败");
						}
						});
					}else if(Grade==-1){
						mui.alert("密码长度必须大于8位且小于20位");
					}else{
						if(Grade==0){
							mui.alert("密码长度必须大于8位且小于20位");
						}else{
							mui.alert("密码必须同时包含：字母、数字、符号");
						}
					}
				}else{
					mui.alert("两次密码不一致！");
				}
			})
		}
		//验证密码复杂度
		function checkPass(password){
    	     if(password.length < 8){
    	        return 0;
    	     }
    	    if(password.length >20)
    	    {
    	    	 return -1;
    	    }
    	    var grade= 0;
    	    if(password.match(/([a-z])+/)){
    	    	grade++;
    	   	 }
    	    if(password.match(/([0-9])+/)){
    	   		grade++;
    	    }   
    	    if(password.match(/([A-Z])+/)){ 
    	   		grade++;
    	     }
    	    if(password.match(/[^a-zA-Z0-9]+/)){
    	     	grade++;
    	    }
    	    return grade;
    }
		</script>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">修改密码</h1>
		</header>
		<div class="mui-content">
		    <div class="oldpassword_model">
				<div>
					<span>&nbsp;&nbsp;旧密码:</span>
					<input type="text" name="oldpassword" id="oldpassword" value="" placeholder="旧密码"/>
				</div>
			</div>
			<div class="newpassword_model">
				<span>&nbsp;&nbsp;新密码:</span>
				<input type="password" name="newpassword" id="newpassword" value="" placeholder="新密码"/>
			</div>
			<div class="truepassword_model">
				<span>&nbsp;&nbsp;确认新密码:</span>
				<input type="password" name="truepassword" id="truepassword" value="" placeholder="确认新密码"/>
			</div>
			<div class="change_password">
				<input  id="forceupdate_but" type="button" value="确定"></input>
			</div>
			
			<div class="row">
				<div class="alert alert-info" style="margin-top: 50px;padding-left: 20px;">
					<p>登录密码修改规则说明：</p>
					<p>1.密码长度为8~20位。</p>
					<p>2.至少包含数字、字母、特殊符号</p>
				</div>
			</div>
		</div>
			
	</body>
</html>